//
//  WithdrawRecordCell.swift
//  MT
//
//  Created by 陈悦 on 2020/5/9.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class WithdrawRecordCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    var model: MTWithdrawReportSubModel? {
        didSet {
            if model != nil {
                detailLabel.text = "-\(model?.amount ?? 0)"
                amountLabel.text = "+\(model?.rmbAmount ?? 0)元"
                timeLab.text = model?.createTime
                titleLabel.text = "提现(比例\(model?.rate ?? 0)%"
            }
        }
    }

    lazy var titleLabel: UILabel = {
        let l = UILabel()
        l.textColor = UIColor(hex:0x1d1a1a)
        l.font = PingFangSCSemiboldFont(14)
        l.text = "提现（比例30%）"
        return l
    }()
    
    lazy var detailLabel: UILabel = {
        let l = UILabel()
        l.textColor = UIColor(hex:0x1d1a1a)
        l.font = PingFangSCSemiboldFont(16)
        l.text = "-10000"
        return l
    }()
    
    lazy var timeLab: UILabel = {
        let lab = UILabel()
        lab.textColor = UIColor(hex:0x9b9b9b)
        lab.font = PingFangSCMediumFont(10)
        lab.text = "2020-4-20  20:30"
        return lab
    }()
    
    lazy var moneyLabel: UILabel = {
        let l = UILabel()
        l.textColor = UIColor(hex:0x1d1a1a)
        l.font = PingFangSCMediumFont(12)
        l.text = "到账金额"
        l.textAlignment = .right
        return l
    }()
    
    lazy var rightIcon: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "dimond")
        return imageView
    }()
    
    lazy var amountLabel: UILabel = {
        let l = UILabel()
        l.textColor = UIColor(hex:0x1d1a1a)
        l.font = PingFangSCMediumFont(12)
        l.text = "+3000元"
        l.textAlignment = .right
        return l
    }()
    
    lazy var lineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex:0xd8d8d8)
        return v
    }()
    
    
    class func reuseIdentity() -> String {
        return "WithdrawRecordCellID"
    }
    
    func bind(model: MTLuckyReportSubModel) {
            
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        makeConstraint()
        contentView.backgroundColor = UIColor.theme.background
        backgroundColor = UIColor.theme.background
    }
    
    private func setupUI() {
        contentView.addSubview(detailLabel)
        contentView.addSubview(lineView)
        contentView.addSubview(moneyLabel)
        contentView.addSubview(rightIcon)
        contentView.addSubview(timeLab)
        contentView.addSubview(titleLabel)
        contentView.addSubview(amountLabel)
    }
    
    private func makeConstraint() {
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(contentView).offset(10)
            make.left.equalTo(contentView).offset(10)
        }
        
        detailLabel.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(2)
            make.left.equalTo(titleLabel)
        }
        
        rightIcon.snp.makeConstraints { (make) in
            make.centerY.equalTo(detailLabel)
            make.left.equalTo(detailLabel.snp.right)
            make.width.height.equalTo(24)
        }
        
        timeLab.snp.makeConstraints { (make) in
            make.top.equalTo(detailLabel.snp.bottom)
            make.left.equalTo(detailLabel)
        }
    
        
        moneyLabel.snp.makeConstraints { (make) in
            make.right.equalTo(contentView).offset(-20)
            make.top.equalTo(contentView).offset(28)
        }
        
        amountLabel.snp.makeConstraints { (make) in
            make.right.equalTo(contentView).offset(-20)
            make.top.equalTo(moneyLabel.snp.bottom)
        }
    

        lineView.snp.makeConstraints { (make) in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(0.5)
        }
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

}
